/**
 * 
 */
package org.cuny.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

/**
 * @author di.wd
 *
 */
public class FileUtil
{
	/**
	 * @param fileName
	 * @return
	 */
	public final static String[] readFileByLines( String fileName )
	{
		FileReader fileReader = null;
		BufferedReader bufferedReader = null;
		ArrayList< String > datas = new ArrayList< String >();
		try 
		{
			fileReader = new FileReader( new File( fileName ) );
			bufferedReader = new BufferedReader( fileReader );
			
			String data = null;
			while ( ( data = bufferedReader.readLine() ) != null )
			{
				datas.add( data );
			}
			
			bufferedReader.close();
			fileReader.close();
			
			return datas.toArray( new String[]{} );
		} 
		catch ( IOException e )
		{
			return new String[ 0 ];
		}
		finally
		{
			try
			{
				if ( bufferedReader != null )
				{
					bufferedReader.close();
				}
				
				if ( fileReader != null )
				{
					fileReader.close();
				}
			}
			catch ( IOException e )
			{
			}
		}
	}
	
	/**
	 * @param args
	 */
	public static void main( String[] args )
	{
		String[] datas = FileUtil.readFileByLines( "D:\\help\\Personal\\cost1.txt" );
		int length = datas.length;
		for ( int i = 0; i < length; i++ )
		{
			System.out.println( datas[ i ] );
		}
	}
}
